function gpsCollection(){
	this.rawGPSData = [];
	this.cleanGPSData = [];
	this.distanceTraveled=0;
	this.verticalTraveled=0;
	this.GPSCount=0;
	
	this.startTally=false;
	this.skipFirst=false;
	this.simulateGPS=false;
	
	this.altitudeMeasurement = "METERS";
	this.distanceMeasurement = "KM";
	this.smoothingNodesCount = 6;
	
	
}
gpsCollection.prototype.setTally = function(bool){
	this.startTally = bool;
}
gpsCollection.prototype.simulate = function(){
	this.simulateGPS = true;
}
	
gpsCollection.prototype.currentNode = function(){
	if (typeof this.cleanGPSData[this.cleanGPSData.length - 1] == "undefined") {
		return 0;
	}
	else {
		return this.cleanGPSData[this.cleanGPSData.length - 1];
	}
}
gpsCollection.prototype.isReady = function(){
	if (typeof this.cleanGPSData[this.cleanGPSData.length - 1] == "undefined") {
		return 0;
	}
	else {
		return 1;
	}
}
gpsCollection.prototype.totalDistance = function(){
	return this.distanceTraveled.toFixed(2);
}
gpsCollection.prototype.storeEvent = function(event){
	if (this.simulateGPS){
		
	altAjust = Math.sin(this.rawGPSData.length * Math.PI / 180)*40;
	this.rawGPSData[this.rawGPSData.length] = new rawGPS((event.latitude + (.00005*this.rawGPSData.length)) ,
			event.longitude + (.00001*this.rawGPSData.length),
			event.altitude + altAjust,event.errorCode,event.heading,event.horizAccuracy,event.vertAccuracy,
			event.velocity + 5.54,event.timestamp);
		
	}else
	{
		this.rawGPSData[this.rawGPSData.length] = new rawGPS(event.latitude, event.longitude, event.altitude, event.errorCode, event.heading, event.horizAccuracy, event.vertAccuracy, event.velocity, event.timestamp);	
	}
	
}
gpsCollection.prototype.registerEvent = function(oUnits, totalTime){
try{	
//updateNodeData(this.myTrack,		6,					this.longDist,this.shortDist,this.elapsedTotal,tallyDistance);
//updateNodeData = function(oRoute, this.smoothingNodesCount, longConversion, shortConversion, totalTime, calcTravel){
if(this.rawGPSData.length > 2){
	

		firstNode = this.rawGPSData[this.rawGPSData.length - 1];
		secondNode = this.rawGPSData[this.rawGPSData.length - 2];
		 
		var advSpeed = 0;
		var timeDiff;
		var smoothSpeed = 0;
		var n1=0;
		var n2=0;
		var n3=0;
		var returnDistance;
		
		altDiff = deltaAltitude(firstNode,secondNode,this.altitudeMeasurement);
		fillDeltaAlt(altDiff,firstNode);
		
		returnDistance = distGPS(firstNode, secondNode, this.distanceMeasurement);
		fillDistanceMeasured(returnDistance,firstNode);
		
		
		timeDiff = deltaTime(firstNode, secondNode);//in seconds
		
		
		if (timeDiff > 0 && firstNode.distanceMeasured > 0) {
			//distance in KM over time in hours
			advSpeed = ((firstNode.distanceMeasured)*1000 / (timeDiff)).toFixed(2);
			//advSpeed = (KMtoMiles(firstNode.distanceMeasured) / (timeDiff / 3600)).toFixed(2);
			fillSpeedMeasured(advSpeed,firstNode);
		}
		else{
			//advMetersperSecond = 0;
			fillSpeedMeasured(firstNode.velocity,firstNode);
		}
		
		smoothingTotal = 0;
		for (var i = 1; i < this.smoothingNodesCount + 1; i++) {
			if(this.rawGPSData.length > this.smoothingNodesCount){
				smoothingTotal += 1.0 * this.rawGPSData[this.rawGPSData.length - i].speedMeasured
			}
			else{
				smoothingTotal = 0;
			}
		}
		if (smoothingTotal == 0 || this.smoothingNodesCount == 0){
			smoothSpeed = firstNode.velocity;
		}
		else
			smoothSpeed = smoothingTotal/this.smoothingNodesCount;
		
		fillSmoothVelocity(smoothSpeed,firstNode);
		
		if (this.startTally) {
			if (this.skipFirst) {
				travel = 0
				travelVert = 0
				fillTravelMeasured(travel, firstNode);
				fillTravelVertical(travelVert, firstNode);
			}
			else {
				this.distanceTraveled += firstNode.distanceMeasured * oUnits.longDist;
				this.verticalTraveled += (firstNode.deltaAlt * oUnits.shortDist);
				fillTravelMeasured(this.distanceTraveled, firstNode);
				fillTravelVertical(this.verticalTraveled, firstNode);
				this.skipFirst = false;
			}
		}
		else{
			travel = 0
			travelVert = 0
			fillTravelMeasured(travel, firstNode);
			fillTravelVertical(travelVert, firstNode);
		}
		
		if (firstNode.travelMeasured > 0 && totalTime > 0) {
			avespeed = firstNode.travelMeasured / (totalTime/3600000);
		}
		else {
			avespeed = 0;
		}
		fillAvgSpeed(avespeed, firstNode);
		
		if (this.rawGPSData[this.rawGPSData.length - 1].isGoodFix()) {
			this.cleanGPSData[this.cleanGPSData.length] = this.rawGPSData[this.rawGPSData.length - 1];
			this.GPSCount = this.cleanGPSData.length;
			
			return true;
		}else{
			return false;
		}
}
else{
	return false;
}
		
}
catch(e){
	$('error_area-to-update').innerHTML = "object:";
	$('error_area-to-update').innerHTML += e.message;
 	
}	
}
gpsCollection.prototype.currentNode = function(){
	return this.cleanGPSData[this.cleanGPSData.length - 1];
}
gpsCollection.prototype.getLat = function(){
	if (this.isReady()) {
		return this.currentNode().latitude.toFixed(6);
	}else {return "N/A";}
}
gpsCollection.prototype.getLon = function(){
	if (this.isReady()) {
		return this.currentNode().longitude.toFixed(6);
	}else {return "N/A";}
}

gpsCollection.prototype.getPace = function(oUnits){
	if (this.isReady()) {
		if (this.currentNode().velocityMPH >= 1.0) {					
			return toMilePaceText((this.currentNode().smoothVelocity * oUnits.velocityUnit).toFixed(2));
	}
	else {
		return  "N/A";
	}
	}else {return "N/A";}
}
gpsCollection.prototype.getSpeed = function(oUnits){
	if (this.isReady()) {
		if (this.currentNode().velocityMPH >= 1.0) {					
			return (this.currentNode().smoothVelocity * oUnits.velocityUnit).toFixed(2);
	}
	else {
		return  "N/A";
	}
	}else {return "N/A";}
}
gpsCollection.prototype.getDistance = function(){
	if (this.isReady()) {
		return this.currentNode().travelMeasured.toFixed(2);
	}else {return 0;}
}
gpsCollection.prototype.getVertDistance = function(){
	if (this.isReady()) {
		return this.currentNode().travelVertical.toFixed(2);
	}else {return 0;}
}
gpsCollection.prototype.getAltitude = function(oUnits){
	if (this.isReady()) {
		return (this.currentNode().altitude * oUnits.shortDist).toFixed(2);
	}else {return 0;}
}

gpsCollection.prototype.getAvgSpeed = function(){
	if (this.isReady()) {
		var myVal;
		if (typeof this.currentNode().averageSpeed == "undefined") {
		myVal = "N/A";
	}else{
		myVal = this.currentNode().averageSpeed.toFixed(2);
	}
	
		return myVal;
	}else {return "N/A";}
}
gpsCollection.prototype.getAvgPace = function(oUnits){
	if (this.isReady()) {						
		return toMilePaceText((this.currentNode().averageSpeed).toFixed(2));
	}else {return "N/A";}
}
gpsCollection.prototype.horizAccuracy = function(){
	if (this.isReady()) {
		return this.currentNode().horizAccuracy;
	}else {return 0;}
}
gpsCollection.prototype.vertAccuracy = function(){
	if (this.isReady()) {
		return this.currentNode().vertAccuracy;
	}else {return 0;}
}

gpsCollection.prototype.GPXHeader = function(){
	
	return "Cut and Copy below this line and paste into a blank file. Save as .gpx (Example: FitTrack07.gpx)<br>*************************<br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;gpx version=&quot;1.0&quot;  creator=&quot;FitTrack 0.7 Palm WebOS Application&quot;   xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;   xmlns=&quot;http://www.topografix.com/GPX/1/0&quot; xsi:schemaLocation=&quot;http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd&quot;&gt; &lt;trk&gt;&lt;name&gt;FitTrack Log&lt;/name&gt;&lt;src&gt;Palm WebOS GPS Enabled Device&lt;/src&gt; &lt;trkseg&gt;";
	
}
gpsCollection.prototype.GPXFooter = function(){
	return "&lt;/trkseg&gt;  &lt;/trk&gt;&lt;/gpx&gt;";
}

gpsCollection.prototype.compileGPX = function(){
	var gpxString = this.GPXHeader();
	
	for (var i = 0; i < this.cleanGPSData.length; i++) {
		gpxString += "&lt;trkpt lat=&quot;" + this.cleanGPSData[i].latitude + "&quot; lon=&quot;" + this.cleanGPSData[i].longitude + "&quot;&gt;&lt;ele&gt;" + this.cleanGPSData[i].altitude + "&lt;/ele&gt;  &lt;time&gt;" + this.cleanGPSData[i].dateTime + "&lt;/time&gt;  &lt;desc&gt;Mile Pace:"+ toMilePaceText((this.cleanGPSData[i].smoothVelocity * 2.237).toFixed(2)) + "&lt;/desc&gt;    &lt;/trkpt&gt;</br>";
	}
	gpxString +=  this.GPXFooter();
	
	return gpxString;
	
}
